-
Notifications
You must be signed in to change notification settings - Fork 429
feat(event_handler): enable support for custom deserializer to parse the request body #6601
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(event_handler): enable support for custom deserializer to parse the request body #6601
Conversation
Thanks a lot for your first contribution! Please check out our contributing guidelines and don't hesitate to ask whatever you need. |
Hi @LucasCMFBraga, thanks for working on this PR! I've reviewed it and to me it makes sense for us to add these new parameter to propagate it to DataClasses, but I'm wondering if we're parsing float incorrectly and if it would make sense to make it default here: https://github.com/aws-powertools/powertools-lambda-python/blob/develop/aws_lambda_powertools/utilities/data_classes/common.py#L89 WDYT? |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #6601 +/- ##
========================================
Coverage 96.09% 96.09%
========================================
Files 254 254
Lines 12178 12179 +1
Branches 905 905
========================================
+ Hits 11703 11704 +1
Misses 373 373
Partials 102 102 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
We could set Decimal as the default for parsing numeric values in JSON, but I would also allow the option to pass a custom JSON deserializer for parsing the request body. This isn’t a case of Python parsing floats incorrectly, it’s just the inherent behavior of floating-point precision. |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @LucasCMFBraga tudo bom? 😄
First of all sorry for the delay in reviewing this, I had to prioritize some internal demands. I made some small changes in this PR, especially renaming the name of the parameter and adding examples to make it more clear for customers.
Again, thanks a lot for bringing up this limitation and addressing this.
APPROVED.
Awesome work, congrats on your first merged pull request and thank you for helping improve everyone's experience! |
Issue number: #6600
Summary
This feature allows to pass a custom deserializer to ensure accurate handling of floating-point precision.
Changes
`
from tests.functional.utils import load_even
import json
from decimal import Decimal
app = ApiGatewayResolver(deserializer=partial(json.loads, parse_float=Decimal))
`
User experience
`
app = ApiGatewayResolver(deserializer=partial(json.loads, parse_float=Decimal))
`
Checklist
If your change doesn't seem to apply, please leave them unchecked.
Is this a breaking change?
RFC issue number:
Checklist:
Acknowledgment
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.